﻿using System.Collections.Generic;
using System.Linq;
using JStore.Core.Dtos;
using JStore.Core.Entities;
using JStore.Core.Enums;
using SpeadFrm.ORM;

namespace JStore.Data.Daos
{
    /// <summary>
    ///
    /// </summary>
    public class CardTypeDao : BaseDao<CardType>
    {
        public List<CardType> GetAll()
        {
            var sql = Sql.Builder.Where("1=1");
            return Query(sql).ToList();
        }

        public CardType GetById(int id)
        {
            var sql = Sql.Builder.Where("Id = @0", id);
            return FirstOrDefault(sql);
        }

        public void DeleteById(int id)
        {
            var sql = Sql.Builder.Where("Id = @0", id);
            Delete(sql);
        }

        public List<CardType> GetListByCardClass(int cardClass)
        {
            var sql = Sql.Builder.Where("CardClass = @0", cardClass);
            return Query(sql).ToList();
        }

        public CardType Get(int userTypeId, CardClass member)
        {
            var sql = Sql.Builder.Where("CardClass = @0 AND UserTypeId = @1", member, userTypeId);
            return FirstOrDefault(sql);
        }

        public List<CardType> GetUpdateUserTypeList(int userTypeId, CardClass cardClass)
        {
            var sql = Sql.Builder.Where("UserTypeId > @0 AND CardClass = @1", userTypeId, cardClass);
            return Query(sql).ToList();
        }
    }
}

